package com.web.common.utils;
/**
 * @Author wangzhipeng
 * @Date 2020-08-31 8:56 上午
 * @Description
 */
import java.sql.*;
public class DBUtils {
    static {
        try {
            //加载驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    private static String user = "root";
    private static String pwd = "123";
    private static String url =
            "jdbc:mysql://localhost:3306/WePrevent?"
                    + "useUnicode=true&characterEncoding=utf8"
                    + "&serverTimezone=Asia/Shanghai";
    public static Connection getConnection() {
        try {
            Connection conn =
                    DriverManager.getConnection(
                            url, user, pwd);
            return conn;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public static void close(
            ResultSet rs,Statement stmt,
            Connection conn) {
        if(rs!=null) {
            try{rs.close();}catch(Exception e) {}
        }
        if(stmt!=null) {
            try{stmt.close();}catch(Exception e) {}
        }
        if(conn!=null) {
            try{conn.close();}catch(Exception e) {}
        }
    }

}
